<!--
 * @Author: your name
 * @Date: 2021-04-06 09:58:40
 * @LastEditTime: 2021-04-09 15:10:30
 * @LastEditors: Please set LastEditors
 * @Description: 项目选择
 * @FilePath: \html\src\components\flowset\Formcreated\components\business\project.vue
-->
<template>
  <el-select
    v-model="value"
    placeholder="请选择"
    :disabled="disabled"
    @change="handleSelectChange"
  >
    <el-option
      v-for="item in options"
      :key="item.Id"
      :disabled="disabled"
      :label="item.ProjectName"
      :value="item.Id"
    />
  </el-select>
</template>
<script>
import { getDepartProject } from '@/api/project/project'
export default {
  props: {
    data: {
      type: String,
      default: () => ''
    },
    formData: {
      type: Object,
      default: () => {}
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      options: [],
      value: '',
      unitentitydata: {},
      queryParameter: {
        UserId: '',
        UnitId: ''
      }
    }
  },
  watch: {
    'formData.applydepart.Id': {
      deep: true,
      handler(val) {
        this.getUnitEntityListByIsPermissions()
      }
    }
  },
  mounted() {
    this.value = this.data
  },
  created() {
    this.getUnitEntityListByIsPermissions()
  },
  methods: {
    handleSelectChange(val) {
      this.$emit('update:data', val)
    },
    getUnitEntityListByIsPermissions() {
      if (this.formData) {
        this.queryParameter.OrgId = this.formData.applydepart.Id
      }
      getDepartProject(this.queryParameter).then(res => {
        this.options = res.Data
      })
    }
  }
}
</script>
